﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;

public partial class ShowLeaguerInfo : System.Web.UI.Page
{
    Operation operation = new Operation();
    protected void Page_Load(object sender, EventArgs e)
    {
        /*string id = Request.QueryString["id"].ToString();
        //DataSet ds = operation.SelectLeaguerInfo(id);
        DataSet ds = operation.SelectPublicInfoById(Convert.ToInt32(id),true);
        txtType.Text = ds.Tables[0].Rows[0][1].ToString();
        txtTitle.Text = ds.Tables[0].Rows[0][2].ToString();
        txtInfo.Text = ds.Tables[0].Rows[0][3].ToString();
        txtLinkMan.Text = ds.Tables[0].Rows[0][4].ToString();
        txtTel.Text = ds.Tables[0].Rows[0][5].ToString();*/
    }
    protected void sendMail_Click(object sender, EventArgs e)
    {
        DataSet ds = operation.ValidateEmail(email.Text.Trim());
        if (ds.Tables[0].Rows.Count <= 0)
        {
            WebMessageBox.Show("注册邮箱不存在!");
        }
        else
        {
            string msg = "你好，" + ds.Tables[0].Rows[0][1].ToString() + ",你在科研成果超市的登陆密码是" + ds.Tables[0].Rows[0][2].ToString();
            sendMail(email.Text, msg);
        }
    }
    public void sendMail(string toEmailstring, string body)
    {
        string FROM = "dmdm2802@gmail.com";
        string SUBJECT = "找回密码";
        string BODY = body;
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(FROM, "科研成果超市");
        msg.To.Add(toEmailstring);
        msg.Subject = SUBJECT;
        msg.Body = BODY;
        msg.BodyEncoding = System.Text.Encoding.UTF8;
        msg.IsBodyHtml = false;
        msg.ReplyTo = new MailAddress(FROM);
        //smtp.126.com不可用，所有使用smtp.gmail.com
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.Credentials = new NetworkCredential("dmdm2802", "<pwd>2010");
        smtp.EnableSsl = true;
        try
        {
            smtp.Send(msg);
            WebMessageBox.Show("邮件已经发送,如果你没收到请再次发送或联系管理员");
        }
        catch (Exception e) {
            WebMessageBox.Show("发送邮件失败！请稍后再试或联系管理员");
        }
    }
}
